package com.coisshi.base.module.mqtt.controller;

import cn.dev33.satoken.util.SaResult;
import com.coisshi.base.common.exception.BizException;
import com.coisshi.base.module.mqtt.dto.MqttPublishDto;
import com.coisshi.base.module.mqtt.service.MqttPublisherService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MQTT 发布接口
 */
@Slf4j
@RestController
@RequestMapping("/api/mqtt")
@RequiredArgsConstructor
public class MqttController {

    private final MqttPublisherService publisherService;

    /**
     * 发送 MQTT 消息
     */
    @PostMapping("/publish")
    public SaResult publish(@RequestBody MqttPublishDto dto) throws BizException {
        publisherService.publish(dto);
        return SaResult.ok("消息发布成功");
    }
} 